package com.example.lazyhelper.ui.profile;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.lazyhelper.R;

public class ProfileFragment extends Fragment {

    private ProfileViewModel mProfileViewModel;
    private Context mContext;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        mProfileViewModel = new ViewModelProvider(this).get(ProfileViewModel.class);
        mContext = this.getActivity();
        View root = inflater.inflate(R.layout.fragment_profile, container, false);

        TextView uid = root.findViewById(R.id.user_id);     // 显示ID
        uid.setText(R.string.demo_uid);

        View info = root.findViewById(R.id.profile_info);
        ImageView infoIcon = info.findViewById(R.id.profile_item_image);
        infoIcon.setImageResource(R.mipmap.user_info);
        TextView infoText = info.findViewById(R.id.profile_item_text);
        infoText.setText(R.string.profile_text_info);

        View settings = root.findViewById(R.id.profile_settings);
        ImageView settingsIcon = settings.findViewById(R.id.profile_item_image);
        settingsIcon.setImageResource(R.mipmap.settings);
        TextView settingsText = settings.findViewById(R.id.profile_item_text);
        settingsText.setText(R.string.profile_text_settings);

        View feedback = root.findViewById(R.id.profile_feedback);
        ImageView feedbackIcon = feedback.findViewById(R.id.profile_item_image);
        feedbackIcon.setImageResource(R.mipmap.feedback);
        TextView feedbackText = feedback.findViewById(R.id.profile_item_text);
        feedbackText.setText(R.string.profile_text_feedback);

        info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ProfileActivity.class);
                startActivity(intent);
            }
        });
        settings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, SettingsActivity.class);
                startActivity(intent);
            }
        });
        feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, FeedbackActivity.class);
                startActivity(intent);
            }
        });

        return root;
    }

}